﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.Validation;
using System.Data.Entity.Infrastructure;

namespace EmrLogger
{
    public static class LogAndThrow
    {
        public static void Log(string message)
        {
            Logger.Log(LogLevel.Error, message);
            throw new Exception(message);
        }
        public static void Log(string message, Exception ex)
        {
            if (ex.GetType() == typeof(DbEntityValidationException))
            {
                Logger.Log(LogLevel.Error, message, ex);
                throw new Exception("Error Validation " + message, ex);
            }
            else if (ex.GetType() == typeof(DbUpdateConcurrencyException))
            {
                Logger.Log(LogLevel.Warn, message, ex);
                throw new Exception("Warn Concurrency " + message, ex);
            }
            else
            {
                Logger.Log(LogLevel.Error, message, ex);
                throw new Exception(message, ex);
            }
        }
        public static void Log(LogLevel logLevel, string message, Exception ex)
        {
            Logger.Log(logLevel, message, ex);
            throw new Exception(message, ex);
        }
    }
    public static class Logger
    {
        public static void Log(LogLevel logLevel, string message)
        {
            // ToDo add logging
        }
        public static void Log(LogLevel logLevel, string message, Exception ex)
        {
            // ToDo add logging
        }
        public static void Log(LogLevel logLevel, string message, Exception ex, string format, params object[] args)
        {
            // ToDo add logging
        }
    }
}
